<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;



//后台模块表
class PayPicModel extends Model
{
    //定义一个表名
    protected $table = 'pay_pic';
    //定义主键
    protected $primaryKey = 'id';
	protected $guarded = [];

	//信息
	static function list($id){
		$list = PayPicModel::where('id',$id)->first();
		if($list){
			return $list;
		}else{
			return ['code'=>0,'msg'=>'该信息不存在'];
		}
	}
	//添加
 	static function action_insertt($data){
 		if(PayPicModel::where('name',$data['name'])->first()){
 			return ['code'=>0,'msg'=>'该银行名称已存在'];
		}
 		PayPicModel::create([
			'name' => $data['name'],
			'logo' => $data['logo'],
 			'logo_bg' => $data['logo_bg'],
		]);
	}

	//编辑
	static function action_update($data){
		PayPicModel::where('id',$data['id'])->update([
			'name' => $data['name'],
			'logo' => $data['logo'],
			'logo_bg' => $data['logo_bg'],
		]);
	}

	//数据
	static function result(){
		$list = PayPicModel::where('type',1)->get();
		foreach($list as $k=>$v){
			$data[$k]['id'] = $v['id'];
			$data[$k]['name'] = $v['name'];
			$data[$k]['logo'] = "http://".$_SERVER['HTTP_HOST'].$v['logo'];
			$data[$k]['logo_bg'] = "http://".$_SERVER['HTTP_HOST'].$v['logo_bg'];
		}
		return $data;
	}
}
